<?php
/**
 * Guard 辅助方法
 *
 * Author: ZeonWang
 * Date: 2017/11/14
 * Time: 17:19
 * Created by PhpStorm.
 */

namespace App\Services\Utils;

use App\Http\Models\Admin;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Gate;

class Guard
{
    /**
     * Delegate Gate Method On Auth::guard
     * @example
     *      Guard::matchId($admin_model, $operate_model)
     *
     * @param  string  $method
     * @param  mixed[2]  $parameters
     * @return mixed
     */
    public static function __callStatic($method, array $parameters)
    {
        list($admin, $arguments) = $parameters;

        return Gate::forUser($admin)->check($method, $arguments);
    }

    /**
     * @return Admin|null
     */
    public static function admin()
    {
        return $admin = Auth::guard('admin')->user();
    }
}